package cn.good.yan.try3;

import java.io.IOException;
import java.io.InputStreamReader;

/**
 *  3. 异常处理的改变
 *
 * @author shengren.yan
 * @create 2023-05-01
 */
public class TryTest {

    public static void main(String[] args) {

        // jdk 8 之前的写法
        InputStreamReader reader = null;
        try {
            reader = new InputStreamReader(System.in);
            reader.read();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        // jdk 8 的写法
        try (InputStreamReader reader2 = new InputStreamReader(System.in)) {
            reader2.read();
        } catch (Exception e) {
            e.printStackTrace();
        }

        // jdk 9 的写法
        InputStreamReader reader3 = new InputStreamReader(System.in);
        try (reader3) {
            reader3.read();
        } catch (Exception e) {
            e.printStackTrace();
        }




    }

}
